home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / GDIDEMO.PAK / GDIDEMO.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  4KB  |  179 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1991, 1995 by Borland International, All Rights Reserved
  4. //
  5. //   A GDI demo program
  6. //----------------------------------------------------------------------------
  7. #include <owl/pch.h>
  8. #include <owl/applicat.h>
  9. #include <owl/mdi.h>
  10. #include <string.h>
  11. #include "demobase.h"
  12. #include "line.h"
  13. #include "fontx.h"
  14. #include "bitblt.h"
  15. #include "arty.h"
  16.  
  17. //
  18. // Menu bar constants
  19. //
  20. const int MenuId            =  100;  // Resource Id of the menubar
  21. const int MoveToLineToDemoId=  201;  // Demo->MoveToDemo Id
  22. const int FontDemoId        =  202;  // Demo->Font Demo Id
  23. const int BitBltDemoId      =  203;  // Demo->BitBlt Demo Id
  24. const int ArtyDemoId        =  204;  // Demo->Arty Demo Id
  25.  
  26. const int IconId            =  100;  // Resource Id of the program icon
  27.  
  28. IMPLEMENT_CASTABLE1(TBaseDemoWindow, TWindow);
  29.  
  30. //----------------------------------------------------------------------------
  31.  
  32. //
  33. //
  34. //
  35. class TGdiDemoWindow : public TMDIClient {
  36.   public:
  37.     TGdiDemoWindow() : TMDIClient() { Attr.Style |= WS_TABSTOP; }
  38.  
  39.   protected:
  40.     void SetupWindow();
  41.     void CleanupWindow();
  42.  
  43.     void CmMoveToLineToDemo();
  44.     void CmFontDemo();
  45.     void CmBitBltDemo();
  46.     void CmArtyDemo();
  47.  
  48.     void EvTimer(uint TimerId);
  49.  
  50.   DECLARE_RESPONSE_TABLE(TGdiDemoWindow);
  51. };
  52.  
  53. DEFINE_RESPONSE_TABLE1(TGdiDemoWindow, TMDIClient)
  54.   EV_COMMAND(MoveToLineToDemoId, CmMoveToLineToDemo),
  55.   EV_COMMAND(FontDemoId, CmFontDemo),
  56.   EV_COMMAND(BitBltDemoId, CmBitBltDemo),
  57.   EV_COMMAND(ArtyDemoId, CmArtyDemo),
  58.   EV_WM_TIMER,
  59. END_RESPONSE_TABLE;
  60.  
  61.  
  62. //
  63. // Setup the main demo window, and try to allocate its timer
  64. //
  65. void
  66. TGdiDemoWindow::SetupWindow()
  67. {
  68.   TMDIClient::SetupWindow();
  69.  
  70.   int result = IDRETRY;
  71.   while (SetTimer(0, 50, 0) == 0 && result == IDRETRY)
  72.     result = MessageBox("Could not Create Timer", "GDIDemo", MB_RETRYCANCEL);
  73.   if (result == IDCANCEL)
  74.     PostQuitMessage(0);
  75. }
  76.  
  77. //
  78. //
  79. //
  80. void
  81. TGdiDemoWindow::CleanupWindow()
  82. {
  83.   KillTimer(0);
  84.   TMDIClient::CleanupWindow();
  85. }
  86.  
  87. //
  88. // In response to a demo command, create one of the demo windows as the client
  89. // of an mdi child frame. Turn of the icon for the mdi child to allow the
  90. // client to paint itself when iconic.
  91. //
  92.  
  93. void
  94. TGdiDemoWindow::CmMoveToLineToDemo()
  95. {
  96.   TMDIChild* child = new TMDIChild(*this, "MoveTo/LineTo Window", 
  97.                                    new TMoveToLineToWindow);
  98.   child->SetIcon(0, 0);
  99.   child->Create();
  100. }
  101.  
  102. void
  103. TGdiDemoWindow::CmFontDemo()
  104. {
  105.   TMDIChild* child = new TMDIChild(*this, "Font Window", new TFontWindow);
  106.   child->SetIcon(GetApplication(), 101);
  107.   child->Create();
  108. }
  109.  
  110. void
  111. TGdiDemoWindow::CmBitBltDemo()
  112. {
  113.   TMDIChild* child = new TMDIChild(*this, "BitBlt Window", new TBitBltWindow);
  114.   child->SetIcon(0, 0);
  115.   child->Create();
  116. }
  117.  
  118. void
  119. TGdiDemoWindow::CmArtyDemo()
  120. {
  121.   TMDIChild* child = new TMDIChild(*this, "Arty Window", new TArtyWindow);
  122.   child->SetIcon(0, 0);
  123.   child->Create();
  124. }
  125.  
  126. //
  127. // Get client demo window from mdi child frame using typesafe downcasting
  128. //
  129. void
  130. ChildTimers(TWindow* p, void*)
  131. {
  132.   TFrameWindow* frame = TYPESAFE_DOWNCAST(p, TFrameWindow);
  133.   CHECK(frame);
  134.   TBaseDemoWindow* demoWin = TYPESAFE_DOWNCAST(frame->GetClientWindow(), TBaseDemoWindow);
  135.   CHECK(demoWin);
  136.   demoWin->TimerTick();
  137. }
  138.  
  139. //
  140. // In response to WMTimer messages, each MDI child window's TimerTick
  141. // Method is called.
  142. //
  143. void
  144. TGdiDemoWindow::EvTimer(uint)
  145. {
  146.   ForEach(ChildTimers, 0);
  147. }
  148.  
  149. //----------------------------------------------------------------------------
  150.  
  151. //
  152. //
  153. //
  154. class TGdiDemoApp : public TApplication {
  155.   public:
  156.     TGdiDemoApp() : TApplication() {}
  157.     void InitMainWindow();
  158. };
  159.  
  160. //
  161. //
  162. //
  163. void
  164. TGdiDemoApp::InitMainWindow()
  165. {
  166.   TFrameWindow* fw =  new TMDIFrame("GDI Demo", MenuId, *new TGdiDemoWindow);
  167.   fw->SetIcon(this, IconId);
  168.   SetMainWindow(fw);
  169. }
  170.  
  171. //
  172. //
  173. //
  174. int
  175. OwlMain(int /*argc*/, char* /*argv*/ [])
  176. {
  177.   return TGdiDemoApp().Run();
  178. }
  179.